/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package core.threads.client.inGame;
import core.messages.client.inGame.Msg_Card_Drop;
import core.messages.client.inGame.Msg_Turn_End;
import core.threads.client.Client_Public_Data;
import core.threads.client.Client_Public_MsgBox;
import core.threads.client.Client_Public_Thread;
import models.Card.Card;
import models.Player;


/**
 *
 * @author Invince
 */
public class T_Client_Drop_Phase  extends Thread{
/*----------Attributs-------------------*/
    protected boolean stop;
    protected boolean suspend;

/*----------Public functions------------*/
    @Override
    public void run() {
        /**-----Init-----**/
        String name;
        synchronized(Client_Public_Data.semaMyInfo){
            name=Client_Public_Data.myInfo.getName();
        }
        /**-----Main----**/
        boolean isTurnOver;
        synchronized(Client_Public_Data.semaIsTurnOver){
            isTurnOver=Client_Public_Data.isTurnOver;
        }
        while(isTurnOver==false){
            if(!Client_Public_MsgBox.msgBox_Client_Card_toDrop.isEmpty()){
                Card cardToDrop=Client_Public_MsgBox.msgBox_Client_Card_toDrop.poll();
                Msg_Card_Drop msgCardDrop=new Msg_Card_Drop(name,"Server",cardToDrop.getId());
                Client_Public_MsgBox.msgBox_Client_Send_Msg.offer(msgCardDrop);
            }
            synchronized(Client_Public_Data.semaIsTurnOver){//Attention here
                isTurnOver=Client_Public_Data.isTurnOver;
            }
        }
        /**----End-----**/
        Msg_Turn_End msgTurnEnd=new Msg_Turn_End(name, "Server");
        Client_Public_MsgBox.msgBox_Client_Send_Msg.offer(msgTurnEnd);
        Client_Public_Thread.tClientActiveSkill.suspendT();
        
        Client_Public_Data.myTurnEnd();//结束自己的turn
     }

//    public void stopT(){
//        synchronized(this){
//            this.stop=true;
//        }
//    }
//
//    public void suspendT(){
//        synchronized(this){
//            this.suspend=true;
//        }
//    }
//
//    public void resumeT(){
//        synchronized(this){
//            this.suspend=false;
//        }
//    }
    public void trunOverButtonClick(){
        boolean isShaCasted;
        synchronized(Client_Public_Data.semaIsShaCasted){
            isShaCasted=Client_Public_Data.isShaCasted;
        }
        Player myInfo;
        synchronized(Client_Public_Data.semaMyInfo){
            myInfo=Client_Public_Data.myInfo;
        }

        if(myInfo.getRole().getName().equals("吕蒙") && !isShaCasted){
            synchronized(Client_Public_Data.semaIsTurnOver){
                Client_Public_Data.isTurnOver=true;
            }
            //??????????/将轮次结束button设为不可用
            return;
        }

        int hp=myInfo.getRole().getHp();
        int nbCard=myInfo.getDeckPlayer().size();
        if(hp>=nbCard){
            synchronized(Client_Public_Data.semaIsTurnOver){
                Client_Public_Data.isTurnOver=true;
            }
             //??????????/将轮次结束button设为不可用
        }else{
            synchronized(Client_Public_Data.semaIsTurnOver){
                Client_Public_Data.isTurnOver=false;
            }
        }
    }
/*----------Private functions-----------*/
/*----------Constructor-----------------*/
    public T_Client_Drop_Phase() {
        synchronized(this){
//            this.stop=false;
//            this.suspend=false;
        }
    }
/*----------Gets and sets---------------*/
}
